package cn.edu.njust.mapper;

import cn.edu.njust.pojo.Register;
import cn.edu.njust.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    /**
     * 登陆的基本功能：匹配数据库中的id_no和password
     *
     * @param user
     * @return
     */
    @Select("SELECT * FROM pre_registration_system.user WHERE id_no = #{idNo} AND password = #{password}")
    @ResultMap("userResultMap")
    User selectById(User user);

    /**
     * 根据id（学号）查询用户是否已经存在
     *
     * @param user -
     * @return -
     */
    @Select("SELECT * FROM pre_registration_system.user WHERE id_no = #{idNo}")
    @ResultMap("userResultMap")
    User selectId(User user);

    @Select("select * from pre_registration_system.user where id_no= #{idNo}")
    User selectId01(@Param("idNo") String idNo);

    /**
     *
     */
    @Delete("delete from pre_registration_system.result")
//    @ResultMap("userResultMap")
    void clear();


    /**
     * 查询所有用户，系统管理员除外
     *
     * @return - 用户列表，除去管理员
     */
    @Select("SELECT * FROM pre_registration_system.user WHERE id_no != '000'")
    @ResultMap("userResultMap")
    List<User> selectAll();

    /**
     * 删除用户信息
     *
     * @param idNo
     */
    @Delete("delete from pre_registration_system.user where id_no= #{idNo}")
    int delete01(@Param("idNo") String idNo);

    @Update("update user set password = 123456 where id_no= #{idNo}")
    void reset01(@Param("idNo") String idNo);

    @Update("update user set flag = 1 where id_no= #{idNo}")
    void approveById01(@Param("idNo") String idNo);

    @Update("update user set flag = 2 where id_no= #{idNo}")
    void disapproveById01(@Param("idNo") String idNo);

    /**
     * 查询对应用户的所有成绩记录
     *
     * @return
     */
    @Select("select total_points from pre_registration_system.transcript where id_no= #{idNo}")
    List<Integer> selectAllGrade(@Param("idNo") String idNo);

    /**
     * 根据用户ID查询报名对象
     *
     * @param idNo
     * @return
     */
    @Select("select * from pre_registration_system.pre_registration where id_no = #{idNo}")
    Register selectByIdNo(@Param("idNo") String idNo);

    /**
     * 提交预报名信息
     * 一部分是把信息存入预报名表；另一部分是把user对应的信息更改
     * @param register
     */
    @Insert("insert into pre_registration_system.pre_registration values(#{idNo}, #{use},#{admission},#{language})")
    void add(Register register);

    @Update("update user set status = 1 where id_no= #{idNo}")
    void add01(@Param("idNo") String idNo);

    /**
     * 撤销预报名信息
     * @param register
     */
    @Delete("delete from pre_registration_system.pre_registration where id_no =#{idNo}")
    void remove(Register register);

    @Update("update user set status = 0 where id_no= #{idNo}")
    void remove01(@Param("idNo") String idNo);

    /**
     * 修改Email
     * @param email
     * @param idNo
     */
    @Update("update user set email = #{email} where id_no= #{idNo}")
    void changeUseremail(@Param("email") String email, @Param("idNo") String idNo);

    /**
     * 修改telephone
     * @param telephone
     * @param idNo
     */
    @Update("update user set telephone = #{telephone} where id_no= #{idNo}")
    void changeUsertelephone(@Param("telephone") String telephone, @Param("idNo") String idNo);

    /**
     * 修改password
     * @param password
     * @param idNo
     */
    @Update("update user set password = #{password} where id_no= #{idNo}")
    void changeUserpassword(@Param("password") String password, @Param("idNo") String idNo);
}
